//引入redux
import {createStore,combineReducers} from "redux";
import {INIT_ITEMS,ADD_ITEM,DEL_ITEM} from "../actions";


function reduce(state={items:[]},action){
    switch(action.type){
        case "INIT_ITEMS":
        return {
            ...state,
            items:action.items
        };
        case ADD_ITEM:
        return {
            ...state,
            items: [
            ...state.items,
            action.item
            ]
        };
        case DEL_ITEM:
        return {
            ...state,
            items: state.items.filter(item=>item.ID!=action.ID)
        };
        default:  
        return state
    }
    
}

//创建存储对象

export default createStore(reduce);